package com.xdja.myapplication

import android.animation.ValueAnimator
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_constraint_circle_group.*
import kotlinx.android.synthetic.main.activity_constraint_helper.*
import kotlinx.android.synthetic.main.activity_constraint_layer.*
import kotlinx.android.synthetic.main.activity_constraint_placeholder.*
import kotlin.math.abs
import kotlin.math.sin

class LayoutDemoActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val layoutId = intent.getIntExtra("layoutId", R.layout.activity_layout_demo)
        setContentView(layoutId)


            layer?.setOnClickListener(fun(_: View) {
                val anim = ValueAnimator.ofFloat(0f, 360f)
                anim.addUpdateListener { animation ->
                    val angle = animation.animatedValue as Float
                    layer.rotation = 0f
                    layer.scaleX = 1 + (180 - abs(angle - 180)) / 20f
                    layer.scaleY = 1 + (180 - abs(angle - 180)) / 20f
                    var shiftX = 200 * sin(Math.toRadians((angle * 2).toDouble())).toFloat()
                    var shiftY = 200 * sin(Math.toRadians((angle * 3).toDouble())).toFloat()
                    layer.translationX = shiftX
                    layer.translationY = shiftY
                }
                anim.duration = 4000
                anim.start()
            })





            button?.setOnClickListener {

                placeholder.setContentId(button.id)
            }



        image1?.setOnClickListener {
                tv_group.visibility= if (tv_group.visibility ==View.VISIBLE) View.GONE else View.VISIBLE
            }


    }
}
